local extension = Package("fengqi_standard")
extension.extensionName = "aaa_fengqi"


Fk:loadTranslationTable{
  ["fengqi_standard"] = "标准",
}

--[[
local weiwu = fk.CreateTriggerSkill{
  name = "efengqi__weiwu$",
  events = {fk.TurnEnd},
  on_use = function(self, event, target, player, data)
    local room = player.room
    local skills = room:getTag("efengqi__weiwu_skills")
    if skills == nil then
      skills = {}
      for _, gname in ipairs(Fk.lords) do
        local g = Fk.generals[gname]
        if Fk:canUseGeneral(gname) then
          for _, s in ipairs(g:getSkillNameList(true)) do
            if Fk.skills[s].lordSkill then
              table.insert(skills, s)
            end
          end
        end
      end
      room:setTag("efengqi__weiwu_skills", skills)
    end
    skills = table.filter(skills, function(s) return not player:hasSkill(s, true) end)
    if #skills == 0 or room:askForChoice(player, {"#efengqi__weiwu_lord", "#efengqi__weiwu_change"}, self.name) == "#efengqi__weiwu_change" then
      local p = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper),
        1, 1, "#efengqi__weiwu-choose", self.name, false)[1]
      local victim = room:getPlayerById(p)
      local kingdoms = table.simpleClone(Fk.kingdoms)
      table.removeOne(kingdoms, victim.kingdom)
      local choice = room:askForChoice(player, kingdoms, self.name, nil, false, Fk.kingdoms)
      room:changeKingdom(victim, choice, true)
    else
      local result = room:askForChoice(player, table.random(skills, 3), self.name, nil, true)
      room:handleAddLoseSkills(player, result)
    end
  end,
}
caocao:addSkill(weiwu)
--]]

Fk:loadTranslationTable{
  --[[
  ["efengqi__weiwu"] = "魏武",
  [":efengqi__weiwu"] = "主公技，回合结束时，你可以选择：1.发现一个主公技；2.变更一名角色势力。",
  ["#efengqi__weiwu_lord"] = "发现一个主公技",
  ["#efengqi__weiwu_change"] = "变更一名角色势力",
  ["#efengqi__weiwu-choose"] = "魏武，选择一名角色，变更其势力",
  --]]
}




--[[
local jiwu = fk.CreateTriggerSkill{
  name = "efengqi__jiwu",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.TargetSpecified, fk.Damage},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      if event == fk.TargetSpecified then
        return data.card.trueName == "slash"
      elseif event == fk.Damage then
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.TargetSpecified then
      data.fixedResponseTimes = data.fixedResponseTimes or {}
      data.fixedResponseTimes["jink"] = 1 + player:getMark("@efengqi__jiwu")[1]
    elseif event == fk.Damage then
      local room = player.room
      local all_choices, result = {"1", "2", "3"}, {}
      local n1 = room:askForChoice(player, all_choices, self.name, "#efengqi__jiwu1-ask")
      table.removeOne(all_choices, n1)
      n1 = tonumber(n1)
      table.insert(result, n1)
      local n2 = room:askForChoice(player, all_choices, self.name, "#efengqi__jiwu2-ask")
      table.removeOne(all_choices, n2)
      n2 = tonumber(n2)
      table.insert(result, n2)
      table.insert(result, tonumber(all_choices[1]))
      room:setPlayerMark(player, "@efengqi__jiwu", result)
    end
  end,

  on_acquire = function (self, player, is_start)
    player.room:setPlayerMark(player, "@efengqi__jiwu", {1, 2, 3})
  end,
  on_lose = function (self, player, is_death)
    player.room:setPlayerMark(player, "@efengqi__jiwu", 0)
  end,
}
local jiwu_targetmod = fk.CreateTargetModSkill{
  name = "#efengqi__jiwu_targetmod",
  frequency = Skill.Compulsory,
  extra_target_func = function(self, player, skill)
    if skill.trueName == "slash_skill" and player:hasSkill(jiwu) then
      return player:getMark("@efengqi__jiwu")[2]
    end
  end,
}
local jiwu_attackrange = fk.CreateAttackRangeSkill{
  name = "#efengqi__jiwu_attackrange",
  frequency = Skill.Compulsory,
  correct_func = function (self, from, to)
    if from:hasSkill(jiwu) then
      return from:getMark("@efengqi__jiwu")[3]
    end
    return 0
  end,
}
jiwu:addRelatedSkill(jiwu_targetmod)
jiwu:addRelatedSkill(jiwu_attackrange)
lvbu:addSkill(jiwu)
--]]
Fk:loadTranslationTable{
--[[
  ["efengqi__jiwu"] = "极武",
  [":efengqi__jiwu"] = "锁定技，你使用【杀】的：响应量+1、可指定目标数+2；攻击范围+3；你造成伤害后，可以重新分配数字！",
  ["@efengqi__jiwu"] = "极武",
  ["#efengqi__jiwu1-ask"] = "极武：选择你使用【杀】所需响应数+",
  ["#efengqi__jiwu2-ask"] = "极武：选择你使用【杀】额外指定目标数+",
  --]]
  ["$efengqi__jiwu1"] = "还有哪个敢挑战我！？",
  ["$efengqi__jiwu2"] = "三个齐上，也不是我的对手！",
}






--[[
local zhouyu = General:new(extension, "efengqi__zhouyu", "wu", 3)
local yingzi = fk.CreateTriggerSkill{
  name = "efengqi__yingzi",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      for _, move in ipairs(data) do
        if move.from ~= player.id and move.moveReason == fk.ReasonUse then
          for _, info in ipairs(move.moveInfo) do
            if info.extra_data and info.extra_data.efengqi__yingziCheck then
              return true
            end
          end
        end
      end
    end
  end,
  on_trigger = function (self, event, target, player, data)
    local n = 0
    for _, move in ipairs(data) do
      if move.from ~= player.id and move.moveReason == fk.ReasonUse then
        for _, info in ipairs(move.moveInfo) do
          if info.extra_data and info.extra_data.efengqi__yingziCheck then
            n = n + 1
          end
        end
      end
    end
    for _ = 1, n, 1 do
      if not player:hasSkill(self) then return end
      self:doCost(event, target, player, data)
    end
  end,
  on_use = function (self, event, target, player, data)
    player:drawCards(1, self.name)
  end,

  refresh_events = {fk.DrawInitialCards, fk.AfterDrawInitialCards, fk.AfterCardsMove},
  can_refresh = function (self, event, target, player, data)
    if player:hasSkill(self) then
      if event == fk.DrawInitialCards then
        return true
      elseif event == fk.AfterDrawInitialCards then
        return target ~= player and not target:isKongcheng()
      end
    end
    if event == fk.AfterCardsMove and player.seat == 1 then
      for _, move in ipairs(data) do
        if move.moveReason == fk.ReasonUse then
          return true
        end
      end
    end
  end,
  on_refresh = function (self, event, target, player, data)
    if event == fk.DrawInitialCards then
      if target == player then
        data.num = 0
        player:broadcastSkillInvoke(self.name)
        player.room:notifySkillInvoked(player, self.name, "negative")
      else
        data.num = data.num + 1
      end
    elseif event == fk.AfterDrawInitialCards then
      local room = player.room
      for _, id in ipairs(target:getCardIds("h")) do
        room:setCardMark(Fk:getCardById(id), "@@efengqi__yingzi", 1)
      end
    elseif event == fk.AfterCardsMove then
      for _, move in ipairs(data) do
        if move.moveReason == fk.ReasonUse then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Player.Hand and Fk:getCardById(info.cardId):getMark("@@efengqi__yingzi") ~= 0 then
              info.extra_data = info.extra_data or {}
              info.extra_data.efengqi__yingziCheck = true
              player.room:setCardMark(Fk:getCardById(info.cardId), "@@efengqi__yingzi", 0)
            end
          end
        end
      end
    end
  end,
}
zhouyu:addSkill(yingzi)

---@return integer[]
local getGuyinCard = function ()
  local room = Fk:currentRoom()
  return table.filter(room:getBanner("efengqi__guyin_card") or {}, function(id)
    return room:getCardArea(id) == Card.DiscardPile
  end)
end

local efengqi__guyin = fk.CreateViewAsSkill{
  name = "efengqi__guyin",
  pattern = ".",
  prompt = "#efengqi__guyin",
  expand_pile = function () return getGuyinCard() end,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and table.contains(getGuyinCard(), to_select)
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return nil end
    return Fk:getCardById(cards[1])
  end,
  after_use = function (self, player, use)
    local room = player.room
    if room:getCardArea(use.card) == Card.DiscardPile then
      room:moveCards {
        ids = Card:getIdList(use.card),
        toArea = Card.DrawPile,
        moveReason = fk.ReasonJustMove,
        skillName = self.name,
        moveVisible = true,
        drawPilePosition = math.random(#room.draw_pile+1),
      }
    end
  end,
  enabled_at_play = function(self, player)
    return true
  end,
  enabled_at_response = function (self, player, response)
    if not response and Fk.currentResponsePattern then
      return table.find(getGuyinCard(), function(id)
        return Exppattern:Parse(Fk.currentResponsePattern):match(Fk:getCardById(id))
      end) ~= nil
    end
  end,
}

local efengqi__guyin_trigger = fk.CreateTriggerSkill{
  name = "#efengqi__guyin_trigger",
  anim_type = "support",
  events = {fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and target ~= player and not target.dead and not target:isKongcheng() then
      return target:getMark(self.name) == 0
    end
  end,
  on_cost = function (self, event, target, player, data)
    local cards = player.room:askForCard(target, 1, 1, false, self.name, true, ".", "#efengqi__guyin-card:"..player.id)
    if #cards > 0 then
      self.cost_data = {cards = cards, tos = {target.id}}
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(target, self.name, 1)
    local card = Fk:getCardById(self.cost_data.cards[1])
    room:setCardMark(card, "@@efengqi__guyin", 1)
    local banner = room:getBanner("efengqi__guyin_card") or {}
    table.insertIfNeed(banner, card.id)
    room:setBanner("efengqi__guyin_card", banner)
    room:recover { num = 1, skillName = "efengqi__guyin", who = target, recoverBy = player }
  end,
}
efengqi__guyin:addRelatedSkill(efengqi__guyin_trigger)

zhouyu:addSkill(efengqi__guyin)

Fk:loadTranslationTable{
  ["efengqi__zhouyu"] = "周瑜",
  ["#efengqi__zhouyu"] = "",
  ["designer:efengqi__zhouyu"] = "",
  ["illustrator:efengqi__zhouyu"] = "小新",

  ["efengqi__yingzi"] = "英姿",
  [":efengqi__yingzi"] = "锁定技，你没有初始手牌，其他角色的初始手牌+1。其他角色因使用而失去一张初始手牌时，你摸一张牌。",
  ["@@efengqi__yingzi"] = "英姿",

  ["efengqi__guyin"] = "顾音",
  [":efengqi__guyin"] = "每名其他角色限一次，其他角色回合开始时，其可以将一张手牌标记为“顾”，然后其回复1点体力；你可以如手牌般使用弃牌堆中的“顾”，然后将之从弃牌堆洗入牌堆中。",
  ["#efengqi__guyin-card"] = "顾音：你可以将一张手牌标记为“顾”，然后回复1点体力",
  ["#efengqi__guyin_trigger"] = "顾音",
  ["@@efengqi__guyin"] = "顾",
  ["#efengqi__guyin"] = "顾音：你可以如手牌般使用弃牌堆中的“顾”！",

  ["$efengqi__yingzi1"] = "哈哈哈哈……",
  ["$efengqi__yingzi2"] = "汝等看好了！",
  ["$efengqi__fanjian1"] = "挣扎吧，在血和暗的深渊里！",
  ["$efengqi__fanjian2"] = "痛苦吧，在仇与恨的地狱中！",
  ["~efengqi__zhouyu"] = "既生瑜，何生……",
}
--]]

